// For more information about this file see https://dove.feathersjs.com/guides/cli/service.html
import { authenticate } from '@feathersjs/authentication'

import { hooks as schemaHooks } from '@feathersjs/schema'
import {
  baseInfoDataValidator,
  baseInfoPatchValidator,
  baseInfoQueryValidator,
  baseInfoResolver,
  baseInfoExternalResolver,
  baseInfoDataResolver,
  baseInfoPatchResolver,
  baseInfoQueryResolver
} from './base-info.schema.js'
import { BaseInfoService, getOptions } from './base-info.class.js'
import { baseInfoPath, baseInfoMethods } from './base-info.shared.js'

export * from './base-info.class.js'
export * from './base-info.schema.js'

// A configure function that registers the service and its hooks via `app.configure`
export const baseInfo = (app) => {
  // Register our service on the Feathers application
  app.use(baseInfoPath, new BaseInfoService(getOptions(app)), {
    // A list of all methods this service exposes externally
    methods: baseInfoMethods,
    // You can add additional custom events to be sent to clients here
    events: []
  })
  // Initialize hooks
  app.service(baseInfoPath).hooks({
    around: {
      all: [
        authenticate('jwt'),
        schemaHooks.resolveExternal(baseInfoExternalResolver),
        schemaHooks.resolveResult(baseInfoResolver)
      ]
    },
    before: {
      all: [
        schemaHooks.validateQuery(baseInfoQueryValidator),
        schemaHooks.resolveQuery(baseInfoQueryResolver)
      ],
      find: [],
      get: [],
      create: [
        schemaHooks.validateData(baseInfoDataValidator),
        schemaHooks.resolveData(baseInfoDataResolver)
      ],
      patch: [
        schemaHooks.validateData(baseInfoPatchValidator),
        schemaHooks.resolveData(baseInfoPatchResolver)
      ],
      remove: []
    },
    after: {
      all: []
    },
    error: {
      all: []
    }
  })
}
